<?php 
	require "./include/common.inc.php";	
	require './include/pagination/pagination.func.php';

	$sql = "select count(1) c from `student`";

	//总数据量
	$count = get_one($sql)['c'];

	//每一页数字页码数量
	$size = 5;

	//每一页显示数据量
	$limit = 10;

	//总页码量

	//获取当前页码[限制页码的范围 [1 < 当前页码 < 最大页码] ]
	if( isset($_GET['page']) && $_GET['page'] > 0 ){
	$cur = $_GET['page'];
	}else{
	$cur = 1;
	}

	//根据页码显示显示对应的列表数据
	$offset = ( $cur-1 ) * $limit;

	$sql = "select s.`id` id,s.`name` name,`sex`,`class`,sum(`achi`) sum,avg(`achi`) `avg` from `student` s left join `achievement` a on s.`id`=a.`sid` left join `course` c on c.`id`=a.`cid` group by s.`id`  order by s.`id` limit $offset,$limit";

	$info = get_all($sql);

?>

<!DOCTYPE html>
<html>
<head>
	<title>成绩查询</title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<!-- loading mui -->
	<link rel="stylesheet" type="text/css" href="css/mui.min.css">
	<!-- custorm style -->
	<link rel="stylesheet" type="text/css" href="css/style.css">
	<link rel="stylesheet" href="./include/pagination/page.css">
</head>
<body>
	<!-- 导航栏 -->
	<header id="header" class="mui-bar mui-bar-nav">
		<h1 class="mui-title">奇猿学生课程管理系统</h1>
		<a class="mui-action-back mui-btn mui-btn-blue mui-btn-link mui-btn-nav mui-pull-left" href="javascript:history.go(-1)"><span class="mui-icon mui-icon-left-nav"></span></a>
		<a class="mui-icon mui-icon-bars mui-pull-right" href="#topPopover"></a>
	</header>
	<!-- 右上角弹出菜单 -->
	<div id="topPopover" class="mui-popover">
			<div class="mui-popover-arrow"></div>
			<div class="mui-scroll-wrapper">
				<div class="mui-scroll">
					<ul class="mui-table-view">
						<li class="mui-table-view-cell"><a href="teacher_index.php">首页</a>
						</li>
						<li class="mui-table-view-cell"><a href="vote.html">我要投票</a>
						</li>
						<li class="mui-table-view-cell"><a href="rate.html">我要评价</a>
						</li>
						<li class="mui-table-view-cell"><a href="teacher_message.php">我要留言</a>
						</li>
						<li class="mui-table-view-cell"><a href="payment.html">我要缴费</a>
						</li>
						<li class="mui-table-view-cell"><a href="teacher_center.php">个人中心</a>
						</li>
					</ul>
				</div>
			</div>
		</div>
	</div>
	<!-- 主内容部分 -->
	<div class="content">
		<section class="xueqi">
			<div class="class">
				<label id="classResult">成绩查询</label>
			</div>
		</section>
		<section class="rate_group">
			<table>
				<tr>
					<th>学号</th>
					<th>姓名</th>
					<th>性别</th>
					<th>班级</th>
					<th>总分</th>
					<th>平均分</th>
					<th>分数详情</th>
				</tr>
				<?php foreach($info as $item){ ?>
				<tr>
					<td><?=$item['id']; ?></td>
					<td><?=$item['name']; ?></td>
					<td><?=$item['sex']==1?'男':'女'; ?></td>
					<td><?=$item['class']; ?></td>
					<td><?=$item['sum']; ?></td>
					<td><?=sprintf('%.2f',$item['avg']); ?></td>
					<td><a href="query_student_achi.php">详情</a></td>
				</tr>
				<?php } ?>
				<tr>
					<td colspan= 7 >
						<?php echo pagination($count,$cur,$limit,$size,null); ?>
					</td>
				</tr>
			</table>
	</div>
	<script src="js/mui.min.js"></script>
</body>
</html>